/* GUI CONVERTED from rcsois2.p (converter v1.76) Mon Aug 26 05:13:49 2002 */
/* rcsois2.p - Release Management Customer Schedules                          */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.9.1.34 $                                                               */
/*V8:ConvertMode=Maintenance                                                  */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* REVISION: 8.6            CREATED: 10/22/96   BY: *K004* Kurt De Wit        */
/* REVISION: 8.5      LAST MODIFIED: 07/18/96   BY: *J0ZS* taf                */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: *K001* ejh                */
/* REVISION: 8.6      LAST MODIFIED: 03/15/97   BY: *K04X* Steve Goeke        */
/* REVISION: 8.6      LAST MODIFIED: 07/12/97   BY: *K0DH* Kieu Nguyen        */
/* REVISION: 8.6      LAST MODIFIED: 10/09/97   BY: *K0NV* Kieu Nguyen        */
/* REVISION: 8.6      LAST MODIFIED: 10/10/97   BY: *K0JV* Surendra Kumar     */
/* REVISION: 8.6      LAST MODIFIED: 11/16/97   BY: *K18W* Taek-Soo Chang     */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* Annasaheb Rahane   */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton       */
/* REVISION: 8.6E     LAST MODIFIED: 08/24/98   BY: *L073* Robin McCarthy     */
/* REVISION: 8.6E     LAST MODIFIED: 10/23/98   BY: *L0CF* Jeff Wootton       */
/* REVISION: 9.0      LAST MODIFIED: 03/29/99   BY: *J3BM* Reetu Kapoor       */
/* REVISION: 9.0      LAST MODIFIED: 08/12/99   BY: *J3KJ* Bengt Johansson    */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Patti Gaultney     */
/* REVISION: 9.1      LAST MODIFIED: 10/07/99   BY: *K22T* Kedar Deherkar     */
/* REVISION: 9.1      LAST MODIFIED: 02/25/00   BY: *M0K7* Manish Kulkarni    */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 05/10/00   BY: *L0XK* Thomas Fernandes   */
/* REVISION: 9.1      LAST MODIFIED: 06/16/00   BY: *L0ZM* Abhijeet Thakur    */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 11/08/00   BY: *L12D* Reetu Kapoor       */
/* REVISION: 9.1      LAST MODIFIED: 01/09/01   BY: *L170* Ashwini Ghaisas    */
/* REVISION: 9.1      LAST MODIFIED: 09/30/00   BY: *N0WD* Mudit Mehta        */
/* Revision: 1.9.1.20    BY: Katie Hilbert         DATE: 04/01/01 ECO: *P002* */
/* Revision: 1.9.1.22    BY: Ashwini Ghaisas       DATE: 12/15/01 ECO: *M1LD* */
/* Revision: 1.9.1.26    BY: Dan Herman            DATE: 02/06/02 ECO: *P00G* */
/* Revision: 1.9.1.27    BY: Sandeep Parab         DATE: 06/04/02 ECO: *M1XH* */
/* Revision: 1.9.1.31    BY: Robin McCarthy        DATE: 07/02/02 ECO: *P0B2* */
/* Revision: 1.9.1.32    BY: Samir Bavkar          DATE: 07/07/02 ECO: *P0B0* */
/* Revision: 1.9.1.33    BY: Robin McCarthy        DATE: 07/15/02 ECO: *P0BJ* */
/* $Revision: 1.9.1.34 $          BY: John Corda            DATE: 08/07/02 ECO: *N1QP* */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

         /* rcsois2.p CUSTOMER SCHEDULING CONFIRM SHIPPER               */

         /* CHANGES MADE TO THIS PROGRAM NEED TO BE MADE TO rcsois.p AS WELL  */

         /* SHIPPER CONFIRM */

         /* THIS PROGRAM IS A COPY OF RCSOIS.P IN ORDER TO AUTOMATICALLY */
         /* SHIP GOODS FOR DIRECT DELIVERY SALES ORDERS.*/

         /* PATCH K001 NEEDS TO BE INSTALLED SINCE IT ADDS GL DAYBOOKS        */
         /* PATCH J0ZS HAS TO BE INSTALLED SINCE IT CORRECTS AN ERROR         */
         /* PATCH G1XY WILL NOT HAVE TO BE INSTALLED BECAUSE IT HAS NO EFFECT */
         /* PATCH H0MD DOESN'T HAVE TO BE INSTALLED SINCE NO POSING IS DONE   */
         /* PATCH G2CR HAS NOT TO BE INSTALLED BECAUSE NO POSTING IS DONE HERE*/
         /* PATCH J12V NEED NOT TO BE INSTALLED SINCE IT CONCERNS PRESHIPPERS */
         /* PATCH K005 DIDN'T HAVE TO BE INSTALLED SINCE IT CONCERNS SCHEDULES*/
         /* ALL PREVIOUS PATCHES ARE INSTALLED (BEFORE 85 ) !!!!!!!!!!!!!!!!! */

{mfdeclre.i}
{cxcustom.i "RCSOIS2.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rcsois2_p_1 "Use Shipper Nbr for Inv Nbr"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_2 "Unit Margin"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_3 "Unit Cost"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_4 "Post Invoice"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_5 "Conversion"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_6 "Invoice"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_7 "Print Invoice"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_8 "Ext Price"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_9 "Print Lot/Serial Numbers Shipped"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_10 "Debit Amount"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_11 "Credit Amount"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_12 "Ext Margin"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_13 "Effective"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_14 "Consolidated/Detail"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcsois2_p_15 "Consolidate Invoices"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

{gldydef.i new}
{gldynrm.i new}

/* THE INPUT VARIABLES CORRESPOND TO THE SHIPFROM AND SHIPPER ID */
/* FROM THE SO SHIPPER THAT YOU WANT TO CONFIRM (SHIP)           */
define input parameter p-ship-addr          like abs_shipfrom.
define input parameter p-ship-id            like abs_id.
define input parameter l_ship-dt            like so_ship_date no-undo.
define input parameter l_eff-dt             like glt_effdate  no-undo.

/* NEW SHARED VARIABLES, BUFFERS AND FRAMES */
define new shared variable rndmthd          like rnd_rnd_mthd.
define new shared variable abs_carr_ref       as character.
define new shared variable abs_fob          like so_fob.
define new shared variable abs_recid          as recid.
define new shared variable abs_shipvia      like so_shipvia.
define new shared variable accum_wip        like tr_gl_amt.
define new shared variable addr             like tr_addr.
define new shared variable already_posted   like glt_amt.
define new shared variable auto_inv         like mfc_logical
   label {&rcsois2_p_7}.
define new shared variable auto_post        like mfc_logical
   label {&rcsois2_p_4}.
define new shared variable base_amt         like ar_amt.
define new shared variable batch            like ar_batch.
define new shared variable batch_tot        like glt_amt.
define new shared variable bill             like so_bill.
define new shared variable bill1            like so_bill.
define new shared variable change_db        like mfc_logical.
define new shared variable consolidate      like mfc_logical
   label {&rcsois2_p_15}.
define new shared variable conv             like um_conv
   label {&rcsois2_p_5} no-undo.
define new shared variable copyusr          like mfc_logical.
define new shared variable cr_acct          like trgl_cr_acct.
define new shared variable cr_sub           like trgl_cr_sub .
define new shared variable cr_amt             as decimal
   format "->>>,>>>,>>>.99" label {&rcsois2_p_11}.
define new shared variable cr_cc            like trgl_cr_cc.
define new shared variable cr_proj          like trgl_cr_proj.
define new shared variable curr_amt         like glt_amt.
define new shared variable cust             like so_cust.
define new shared variable cust1            like so_cust.
define new shared variable desc1            like pt_desc1
   format "x(49)".
define new shared variable dr_acct          like trgl_dr_acct.
define new shared variable dr_sub           like trgl_dr_sub .
define new shared variable dr_amt             as decimal
   format "->>>,>>>,>>>.99" label {&rcsois2_p_10}.
define new shared variable dr_cc            like trgl_dr_cc.
define new shared variable eff_date         like glt_effdate
   label {&rcsois2_p_13}.
define new shared variable exch_rate        like exr_rate.
define new shared variable exch_rate2       like exr_rate2.
define new shared variable exch_ratetype    like exr_ratetype.
define new shared variable exch_exru_seq    like exru_seq.
define new shared variable ext_cost         like sod_price.
define new shared variable ext_disc           as decimal decimals 2.
define new shared variable gr_margin        like sod_price
   label {&rcsois2_p_2} format "->>>>,>>9.99".
define new shared variable ext_gr_margin    like gr_margin
   label {&rcsois2_p_12}.
define new shared variable base_margin      like ext_gr_margin.
define new shared variable ext_list         like sod_list_pr
   decimals 2.
define new shared variable ext_price          as decimal
   label {&rcsois2_p_8} decimals 2 format "->>>>,>>>,>>9.99".
define new shared variable base_price       like ext_price.
define new shared variable fas_so_rec         as character.
define new shared variable freight_ok       like mfc_logical.
define new shared variable gl_amt           like sod_fr_chg.
define new shared variable gl_sum           like mfc_logical
   format {&rcsois2_p_14} initial yes.
define new shared variable inv              like ar_nbr
   label {&rcsois2_p_6}.
define new shared variable inv1             like ar_nbr
   label {t001.i}.
define new shared variable inv_only         like mfc_logical
   initial yes.
define new shared variable issrct             as character
   format "x(3)".
define new shared variable issue            like mfc_logical.
define new shared variable loc              like pt_loc.
define new shared variable lot_ser          like pt_lot_ser.
define new shared variable lotserial_qty    like sr_qty no-undo.
define new shared variable lotserial_total  like tr_qty_chg.
define new shared variable name             like ad_name.
define new shared variable nbr              like tr_nbr.
define new shared variable net_price        like sod_price.
define new shared variable net_list         like sod_list_pr.
define new shared variable old_ft_type        as character.
define new shared variable open_ref         like sod_qty_ord.
define new shared variable ord-db-cmtype    like cm_type no-undo.
define new shared variable order_ct           as integer.
define new shared variable order_nbrs         as character extent 30.
define new shared variable order_nbr_list     as character no-undo.
define new shared variable orderline        like tr_line.
define new shared variable ordernbr         like tr_nbr.
define new shared variable part               as character
   format "x(18)".
define new shared variable post             like mfc_logical.
define new shared variable post_entity      like ar_entity.
define new shared variable prev_consume     like sod_consume.
define new shared variable prev_qty_ord     like sod_qty_ord.
define new shared variable prev_due         like sod_due_date.
define new shared variable prev_site        like sod_site.
define new shared variable prev_type        like sod_type.
define new shared variable print_lotserials like mfc_logical
   label {&rcsois2_p_9}.
define new shared variable project          like wo_project.
define new shared variable pt_recid           as recid.
define new shared variable que-doc            as logical.
define new shared variable qty                as decimal.
define new shared variable qty_all          like sod_qty_all.
define new shared variable qty_pick          like sod_qty_pick.
define new shared variable qty_bo           like sod_bo_chg.
define new shared variable qty_chg          like sod_qty_chg.
define new shared variable qty_cum_ship     like sod_qty_ship.
define new shared variable qty_inv          like sod_qty_inv.
define new shared variable qty_iss_rcv      like tr_qty_loc.
define new shared variable qty_left         like tr_qty_chg.
define new shared variable qty_open         like sod_qty_ord.
define new shared variable qty_ord          like sod_qty_ord.
define new shared variable qty_req          like in_qty_req.
define new shared variable qty_ship         like sod_qty_ship.
define new shared variable ref              like glt_ref.
define new shared variable rejected         like mfc_logical no-undo.
define new shared variable rmks             like tr_rmks.
define new shared variable sct_recid          as recid.
define new shared variable sct_recno          as recid.
define new shared variable ship_db          like global_db.
define new shared variable ship_dt          like so_ship_date.
define new shared variable ship_line        like sod_line.
define new shared variable ship_site          as character.
define new shared variable ship_so          like so_nbr.
define new shared variable should_be_posted like glt_amt.
define new shared variable so_db            like global_db.
define new shared variable so_job           like tr_so_job.
define new shared variable so_hist          like soc_so_hist.
define new shared variable so_mstr_recid      as recid.
define new shared variable so_recno           as recid.
define new shared variable sod_entity       like en_entity.
define new shared variable sod_recno          as recid.
define new shared variable std_cost         like sod_std_cost.
define new shared variable tax_recno          as recid.
define new shared variable tot_curr_amt     like glt_amt.
define new shared variable tot_ext_cost     like sod_price.
define new shared variable tot_line_disc      as decimal decimals 2.
define new shared variable tr_recno           as recid.
define new shared variable transtype          as character
   format "x(7)".
define new shared variable trgl_recno         as recid.
define new shared variable trlot            like tr_lot.
define new shared variable trqty            like tr_qty_chg.
define new shared variable unit_cost        like tr_price
   label {&rcsois2_p_3}.
define new shared variable undo_all         like mfc_logical no-undo.
define new shared variable use_shipper      like mfc_logical
   label {&rcsois2_p_1}.
define new shared variable wip_entity       like si_entity.
define new shared variable yn               like mfc_logical.
define new shared variable l_undo           like mfc_logical no-undo.
define new shared workfile work_sr_wkfl     like sr_wkfl.

/* SHARED VARIABLES, BUFFERS AND FRAMES */
define shared variable global_recid           as recid.
define shared variable confirm_mode like mfc_logical no-undo.
define shared variable l_recalc like mfc_logical no-undo initial yes.

/* LOCAL VARIABLES, BUFFERS AND FRAMES */
define variable abs_trans_mode                as character.
define variable abs_veh_ref                   as character.
define variable cust_id                       as character.
define variable first_so_bill               like so_bill.
define variable first_so_cust               like so_cust.
define variable first_so_curr               like so_curr.
define variable first_so_cr_terms           like so_cr_terms.
define variable first_so_slspsn             like so_slspsn.
define variable first_so_trl1_cd            like so_trl1_cd.
define variable first_so_trl2_cd            like so_trl2_cd.
define variable first_so_trl3_cd            like so_trl3_cd.
define variable msg_text                      as character.
define variable qty_to_ship                   as decimal.
define variable shipqty                       as decimal no-undo.
define variable ship_id                       as character.
define variable txcalcref                     as character.
define variable oldcurr                     like so_curr.
define variable sr_recid                      as recid.
define variable undo_stat        like mfc_logical no-undo.
define variable l_tr_type like tx2d_tr_type initial "13" no-undo.
define variable l_nbr     like tx2d_nbr     initial ""   no-undo.
define variable l_line    like tx2d_line    initial 0    no-undo.

define new shared temp-table work_ldd no-undo
   field work_ldd_id like abs_mstr.abs_id
   index work_ldd_id work_ldd_id .

define variable l_consigned_line_item like mfc_logical no-undo.
define temp-table tt_consign_rec
   field tt_consign_order like so_nbr
   field tt_consign_line like sod_line
   field tt_consign_qty_chg like sod_qty_chg
   index tt_consign_rec_idx tt_consign_order tt_consign_line.

{rcwabsdf.i new}
{fsdeclr.i new}
{gpglefdf.i}
{txcalvar.i}
/* Euro Tool Kit definitions */
{etvar.i &new="new"}
{etdcrvar.i "new"}
{etrpvar.i &new="new"}
{etsotrla.i "new"}

/* CONSIGNMENT VARIABLES */
{socnvars.i}

/* FREIGHT ACCRUAL TEMP TABLE DEFINITION */
{lafrttmp.i "new"}

/* DETERMINE IF CUSTOMER CONSIGNMENT IS ACTIVE */
{gprun.i ""gpmfc01.p""
   "(input ENABLE_CUSTOMER_CONSIGNMENT,
     input 10,
     input ADG,
     input CUST_CONSIGN_CTRL_TABLE,
     output using_cust_consignment)"}
/*GUI*/ if global-beam-me-up then undo, leave.


for first gl_ctrl
      fields (gl_base_curr gl_rnd_mthd) no-lock:
end. /* FOR FIRST GL_CTRL */

/* SETTING OF THESE VARIABLES BECAUSE NO INTERFACE IS USED */
assign
   auto_post   = no
   use_shipper = no
   consolidate = no.

for first abs_mstr
      fields (abs_id abs_inv_mov abs_qty abs_shipfrom abs_shipto
              abs_ship_qty abs_status abs_type abs__qad01)
      where abs_shipfrom = p-ship-addr
      and   abs_id       = p-ship-id no-lock:
end. /* FOR FIRST ABS_MSTR */

if not available abs_mstr then return.
/* THE RETURN OPTION IS USED IN THIS PROGRAM BECAUSE NO INTERFACE   */
/* IS USED*/

if abs_type <> "s"
   or not abs_id begins "s" then return.

for first si_mstr
      fields (si_db si_site)
      where si_site = abs_shipfrom no-lock:
end. /* FOR FIRST SI_MSTR */

if not available si_mstr then do:
   {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}   /* site doesn't exist */
   return.
end.

/* Making sure db is connected */
if si_db <> global_db and not connected(si_db) then do:
   {mfmsg03.i 2510 3 si_db """" """"}  /*db # not connected*/
   return.
end.

{gprun.i ""gpsiver.p""
   "(input abs_shipfrom, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

if return_int = 0 then do:
   {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3} /* USER DOES NOT HAVE ACCESS TO SITE */
   return.
end.

if substring(abs_status,2,1) = "y" then do:
   {pxmsg.i &MSGNUM=8146 &ERRORLEVEL=3} /* SHIPPER PREVIOUSLY CONFIRMED */
   return.
end.

{&RCSOIS2-P-TAG1}
if abs_inv_mov <> "" and
   not can-find
   (first im_mstr where
   im_inv_mov = abs_inv_mov and
   im_tr_type = "ISS-SO")
then do:
   {&RCSOIS2-P-TAG2}
   {pxmsg.i &MSGNUM=5802 &ERRORLEVEL=3} /* Not a sales order shipper */
   return.
end.  /* if abs_inv_mov */

if substring(abs_status,1,1) <> "y" then do:
   {pxmsg.i &MSGNUM=8147 &ERRORLEVEL=2}
   bell.
end.

assign
   abs_recid    = recid(abs_mstr)
   global_site  = abs_shipfrom
   global_lot   = abs_id
   ship_dt      = l_ship-dt
   eff_date     = l_eff-dt
   oldcurr      = "".

/*       MOVED FROM BELOW SO THAT "SHIPMENT OF BTB SO WITH PENDING  **
**       CHANGE NOT ALLOWED" MESSAGE CAN APPEAR BEFORE PROMPTING    **
**       FOR EFFECTIVE DATE                                         */
for each work_abs_mstr exclusive-lock:
   delete work_abs_mstr.
end.

/* EXPLODE SHIPPER TO GET ORDER DETAIL */
{gprun.i ""rcsoisa.p"" "(input recid(abs_mstr))"}
/*GUI*/ if global-beam-me-up then undo, leave.


/* ADD CONSIGNMENT DATA TO work_abs_mstr */
if using_cust_consignment then do:
   {gprunmo.i &module = "ACN" &program = "rcsoisa2.p"}
end.  /* if using_cust_consignment */

/*EXIT IF THERE IS ANY PENDING CHANGE FOR BTB ORDER */
assign que-doc = no.
for each work_abs_mstr no-lock break by work_abs_mstr.abs_order
      on endkey undo, return:
   if first-of (work_abs_mstr.abs_order) and
      work_abs_mstr.abs_order <> ""
   then do:

      for first so_mstr
         fields (so_bill so_cr_terms so_curr so_cust so_exru_seq
                 so_ex_rate so_ex_rate2 so_ex_ratetype so_fix_rate
                 so_fr_list so_fr_terms so_invoiced so_nbr
                 so_primary so_ship_date so_slspsn so_stat
                 so_tax_date so_to_inv so_trl1_cd so_trl2_cd
                 so_trl3_cd so_disc_pct so_pst_pct so_quote
                 so_tax_pct so_trl1_amt so_trl2_amt so_trl3_amt)
         where so_nbr = abs_order no-lock:
      end. /* FOR FIRST SO_MSTR */

      for first sod_det
            fields (sod_btb_po sod_line sod_nbr sod_part sod_qty_chg
                    sod_site sod_std_cost sod_um_conv)
            where sod_nbr  = abs_order
            and sod_line   = integer(abs_line) no-lock:
      end. /* FOR FIRST SOD_DET */

      if so_primary
      then
         for first cmf_mstr
            fields (cmf_doc_ref cmf_doc_type cmf_status)
            where  cmf_doc_type = "PO"
            and  cmf_doc_ref  = sod_btb_po
            and (cmf_status   = "1" or
            cmf_status   = "2" or
            cmf_status   = "3"    )

            no-lock:
      end. /* FOR FIRST CMF_MSTR */

      else
      for first cmf_mstr
            fields (cmf_doc_ref cmf_doc_type cmf_status)
            where cmf_doc_type = "SO"
            and cmf_doc_ref  = so_nbr
            and cmf_status   = "1"

            no-lock:
      end. /* FOR FIRST CMF_MSTR */

      if available cmf_mstr then do:
         {pxmsg.i &MSGNUM=2834 &ERRORLEVEL=3}
         /* CHANGE ON BTB SO WITH PENDING CHANGE IS NOT ALLOWED */
         undo, return.
      end. /* available cmf_mstr */

      /* THIS IS THE SHIPMENT OF A BACK TO BACK DIRECT  */
      /* DELIVERY SO. THIS FUNCTION IS ONLY RAN WHEN   */
      /* THE CORRESPONDING BACK TO BACK PO IS RECEIVED. */
      /* WHEN THE CORRESPONDING END CUSTOMER IS AN EDI */
      /* PARTNER THEN WE HAVE TO SEND HIM AN ASN.       */
      /* THEREFORE THIS IS ONLY DONE WHEN WHERE USING  */
      /* THE PRIMARY SALES ORDER.                       */

      /* THIS IS DIFFERENT IN THE PROGRAM rcsois.p !!!! */

      /* CHECK IF EDI PARTNER LATER.  */
      if so_primary = yes and que-doc = no then que-doc = yes.

   end. /* if first-of(abs_order) */

end. /* for each work_abs_mstr */

for first ad_mstr
      fields (ad_addr ad_ref)
      where ad_addr = abs_shipto no-lock:
end. /* FOR FIRST AD_MSTR */
assign
   cust_id = ""
   ship_id = ad_addr.

for first ls_mstr
      fields (ls_addr ls_type)
      where ls_addr = ad_addr
      and   ls_type = "customer" no-lock:
end. /* FOR FIRST LS_MSTR */

do while not available ls_mstr and ad_ref > "":
   addr = ad_ref.

   for first ad_mstr
         fields (ad_addr ad_ref)
         where ad_addr = addr no-lock:
   end. /* FOR FIRST AD_MSTR */

   for first ls_mstr
         fields (ls_addr ls_type)
         where ls_addr = ad_addr
         and   ls_type = "customer" no-lock:
   end. /* FOR FIRST LS_MSTR */
end.

if available ls_mstr then cust_id = ls_addr.

for first cm_mstr
      fields (cm_addr cm_cr_hold)
      where cm_addr = cust_id no-lock:
end. /* FOR FIRST CM_MSTR */

if cm_cr_hold then do:
   {pxmsg.i &MSGNUM=614 &ERRORLEVEL=2} /* CUSTOMER ON CREDIT HOLD */
end.

assign
   abs_shipvia    = substring(abs__qad01,1,20)
   abs_fob        = substring(abs__qad01,21,20)
   abs_carr_ref   = substring(abs__qad01,41,20)
   abs_trans_mode = substring(abs__qad01,61,20)
   abs_veh_ref    = substring(abs__qad01,81,20).

txcalcref = string(abs_shipfrom,"x(8)") + abs_id.

for first ad_mstr
      fields (ad_addr ad_ref)
      where ad_addr = abs_shipto no-lock:
end. /* FOR FIRST AD_MSTR */

{gpglef01.i ""IC"" glentity eff_date}
{gpglef01.i ""SO"" glentity eff_date}
if gpglef > 0 then do:
   /* IF PERIOD CLOSED THEN WARNING ONLY */
   if gpglef = 3036 then do:
      {pxmsg.i &MSGNUM=3005 &ERRORLEVEL=2}
      /* OTHERWISE REGULAR ERROR MESSAGE */
   end.
   else if gpglef <> 3036 then do:
      {pxmsg.i &MSGNUM=gpglef &ERRORLEVEL=4}
      undo, return.
   end.
end.

/*Warn if there is any sales orders on the shipper that has
it's action status non-blank */

for each work_abs_mstr no-lock
      break by abs_order
      on endkey undo, return:
/*GUI*/ if global-beam-me-up then undo, leave.

   if first-of (abs_order) then do:

      for first so_mstr
         fields (so_bill so_cr_terms so_curr so_cust so_exru_seq
                 so_ex_rate so_ex_rate2 so_ex_ratetype so_fix_rate
                 so_fr_list so_fr_terms so_invoiced so_nbr
                 so_primary so_ship_date so_slspsn so_stat
                 so_tax_date so_to_inv so_trl1_cd so_trl2_cd
                 so_trl3_cd so_disc_pct so_pst_pct so_quote
                 so_tax_pct so_trl1_amt so_trl2_amt so_trl3_amt)
         where so_nbr = abs_order no-lock:
      end. /* FOR FIRST SO_MSTR */

      if available so_mstr and so_stat <> "" then do:
         {pxmsg.i &MSGNUM=623 &ERRORLEVEL=2} /* SALES ORDER STATUS NOT BLANK */
         leave.
      end.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* if first-of  abs_order */
end. /* for each work_abs_mstr */

issue = true.

/* VALIDATES THAT THERE IS ADEQUATE INVENTORY AVAILABLE TO SHIP ALL
LINES WITH SAME SITE, LOC & PART IF OVER-ISSUE NOT ALLOWED */

{gprun.i ""rcsoisg.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

if rejected then
      undo, return.

/* GO THRU WORKFILE FOR  VALIDATION,  UPDATE  STD  COSTS,  SET
PRICES,  SET  INVOICING  FLAGS, UPDATE FREIGHT CHARGES, MANUAL
UPDATE OF TRAILER CHARGES, AND ORDER  THE  SECRETARY  FLOWERS. */

order_ct = 0.

do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


   for each work_abs_mstr no-lock,
         each sod_det exclusive-lock where sod_nbr = abs_order
         and sod_line = integer(abs_line)
         break by sod_nbr by sod_line:
/*GUI*/ if global-beam-me-up then undo, leave.


      if (oldcurr <> so_curr) or (oldcurr = "") then do:

         if so_curr = gl_base_curr then
               rndmthd = gl_rnd_mthd.
         else do:
            /* GET ROUNDING METHOD FROM CURRENCY MASTER */
            {gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
               "(input  so_curr,
                 output rndmthd,
                 output mc-error-number)"}
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=4}
               next.
            end.
         end.

         oldcurr = so_curr.
      end. /* if oldcurr <> so_curr */

      if first-of(sod_nbr) then
      do:
         find so_mstr where so_nbr = sod_nbr exclusive-lock.
         assign
            first_so_bill      = so_bill
            first_so_cust      = so_cust
            first_so_curr      = so_curr
            first_so_cr_terms  = so_cr_terms
            first_so_trl1_cd   = so_trl1_cd
            first_so_trl2_cd   = so_trl2_cd
            first_so_trl3_cd   = so_trl3_cd
            first_so_slspsn[1] = so_slspsn[1]
            first_so_slspsn[2] = so_slspsn[2]
            first_so_slspsn[3] = so_slspsn[3]
            first_so_slspsn[4] = so_slspsn[4].

         /*! MULTI-DB: USE SHIP-TO CUSTOMER TYPE FOR DEFAULT
         IF AVAILABLE ELSE USE BILL-TO TYPE USED TO
         FIND COGS ACCOUNT IN SOCOST02.p */
         {gprun.i ""gpcust.p"" "( input  so_nbr,
                                  output ord-db-cmtype)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.  /* first-of(sod_nbr) */

      /*          FROM THE INITIAL ANALYSIS IT IS NOT CLEAR WHETHER QTY_TO_SHIP
      *          SHOULD BE USING WORK_ABS_MSTR QTY'S INSTEAD OF ABS_MSTR QTY'S
      *          SINCE THE QTY_TO_SHIP IS USED BY FREIGHT COMPUTATION,THE COMPUTATION
      *          MAY BE ERRONEOUS, ANOTHER SR IS BEING CREATED TO LOOK INTO THIS
      *          PROBLEM IN DETAIL. ONCE IT'S DETERMINED THAT FREIGHT CALC CAN BE
      *          BASED ON WORK_ABS_MSTR QTY'S, THE VARIABLE SHIPQTY SHOULD BE
      *          REMOVED AND ITS REFERENCES SHOULD BE REPLACED WITH QTY_TO_SHIP
      */
      assign
         qty_to_ship = work_abs_mstr.abs_qty - work_abs_mstr.abs_ship_qty
         shipqty = work_abs_mstr.abs_qty - work_abs_mstr.abs_ship_qty.
      accumulate qty_to_ship (sub-total by sod_line).
      accumulate shipqty (sub-total by sod_line).

      if first-of(sod_nbr) then do:
         order_ct = order_ct + 1.
         if order_ct <= 30
            then order_nbrs[order_ct] = sod_nbr.
         else order_nbr_list = order_nbr_list + sod_nbr + ",".

         if so_fix_rate then
         assign
            exch_rate     = so_ex_rate
            exch_rate2    = so_ex_rate2
            exch_ratetype = so_ex_ratetype
            exch_exru_seq = so_exru_seq.
         else do:
            /* GET EXCHANGE RATE */
            {gprunp.i "mcpl" "p" "mc-get-ex-rate"
                        "(input so_curr,
                          input base_curr,
                          input so_ex_ratetype,
                          input eff_date,
                          output exch_rate,
                          output exch_rate2,
                          output mc-error-number)"}
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
               undo, return.
            end.
            assign
               exch_ratetype = so_ex_ratetype
               exch_exru_seq = 0.
         end. /* else */

         assign
            so_to_inv = yes
            so_ship_date = ship_dt
            so_invoiced = no
            so_tax_date = ship_dt.
      end. /* first-of(sod_nbr) */

      if last-of(sod_line) then do:
         /* SET STANDARD COST */
         {gpsct05.i &part=sod_part &site=sod_site &cost=sct_cst_tot}
         sod_std_cost = glxcst * sod_um_conv.
      end.

      /* MOVED THE UPDATION TO sod_qty_chg HERE SO THAT   */
      /* IT IS UPDATED FOR ALL SALES ORDER LINES          */
      sod_qty_chg = accum sub-total by sod_line qty_to_ship.

      if last-of(sod_nbr) then do:

         /* CALCULATE FREIGHT WHEN L_RECALC IS SET TO YES */

         if so_fr_list  <> "" and
            so_fr_terms <> "" and
            l_recalc    =  yes
         then do:

            /*CALCULATE FREIGHT CHARGES*/
            for first ft_mstr
                  fields (ft_terms ft_type)
                  where ft_terms = so_fr_terms no-lock:
            end. /* FOR FIRST FT_MSTR */

            if available ft_mstr then old_ft_type = ft_type.
            so_mstr_recid = recid(so_mstr).
            {gprun.i ""sofrcals.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


            if not freight_ok then do:
               {pxmsg.i &MSGNUM=669 &ERRORLEVEL=2}
               /* Freight error detected - */
            end.
         end.  /* so_fr_list <> "" and so_fr_terms <> "" */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* last-of(sod_nbr) */
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* for each work_abs_mstr */

end. /* do transaction */

do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

   {mfnxtsq.i wo_mstr wo_lot woc_sq01 trlot}
end.
/*GUI*/ if global-beam-me-up then undo, leave.


/* Added input using_cust_consignment    */
{gprun.i ""rcsois1a.p"" "(input ""po_shipper_confirm"",
                          input using_cust_consignment,
                          output undo_stat)" }
/*GUI*/ if global-beam-me-up then undo, leave.


if  l_undo
then do:
   if not batchrun
   then
      pause.
   undo, return.
end. /* if l_undo */

if undo_stat
then
   undo, return.

run p_taxcal.
run p_wrk_so_calc.

global_recid = abs_recid.

{rctxcal.i}
